package com.cy.pj.sys.dao;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.cy.pj.common.bo.SysUserDept;
import com.cy.pj.sys.pojo.SysUser;

@Mapper
public interface SysUserDao {
	/** 基于id修改密码和盐值 */
	@Update("update sys_users set password=#{newPwd},salt=#{newSalt},modifiedTime=now(),modifiedUser=#{username} where id=#{id}")
	int updatePaword(	@Param("id") Integer id,
						@Param("username") String username,
						@Param("newPwd") String newPwd, 
						@Param("newSalt") String newSalt);
	
	/** 基于用户名查询用户信息 */
	@Select("select * from sys_users where username=#{username}")
	SysUser findUserByUsername(String username);
	
	//int getRowCount(@Param("username") String username);
	
//	List<SysUserDept> findPageObject(@Param("username") String username,
//									@Param("startIndex") Integer startIndex,
//									@Param("pageSize") Integer pageSize);
	
	List<SysUserDept> findPageObject(@Param("username") String username);
	
	@Update("update sys_users set valid=#{valid},modifiedUser=#{modifiedUser},modifiedTime=now() where id=#{id}")
	int validById(@Param("id")Integer id,@Param("valid")Integer valid,@Param("modifiedUser")String modifiedUser);
	
	int doSaveObject(SysUser sysUser);
	
	SysUserDept findObjectById(Integer id);
	
	int updateObjectById(SysUser sysUser);

	@Select("select count(*) from sys_user where id=#{id}")
	int getUserCountByDeptId(Integer id);
}
